import uuid from 'uuid';
import insert from './atom/db/insert';

declare const action_id: string;
declare const session_id: string;
declare const spaceid: string;

interface Message {
	deptname: string;
	parent_dept_code: string;
	parent_dept_name: string;
}

async function atom(msg: Message) {
	const systemid = '6051';
	const { exec, prepare } = insert(action_id, session_id, spaceid, systemid);
	prepare('dept', [{ _id: uuid(), deptname: msg.deptname, parent_dept_code: msg.parent_dept_code, parent_dept_name: msg.parent_dept_name, deptid: uuid() }]);
	const res = await exec();
	if (res.code === 1) {
		return 'success';
	} else {
		return 'fail';
	}
}